<template>
  <header :active-tab="activeTab" :tabs="tabs">
    <div class="logo-container">
      <img :src="LOGO_URL" alt="60s" class="logo" />
      <div class="title">
        <h1>60s</h1>
      </div>
    </div>
    <nav class="nav-tabs">
      <button
          v-for="tab in tabs"
          :key="tab.id"
          :class="['tab-btn', { active: activeTab === tab.id }]"
          @click="switchTab(tab.id)"
      >
        {{ tab.name }}
      </button>
    </nav>
    <div class="right-icons">
      <button class="icon-btn" @click="refreshCurrentTab">
        <i class="refresh-icon">
          <SyncOutlined :style="{ fontSize:'25px',color: '#6b57be'}"/>
      </i>
      </button>
      <button class="icon-btn">
        <a class="cat-icon" :href="GITHUB_URL" target="_blank" rel="noopener noreferrer">
          <GithubFilled :style="{ fontSize:'25px',color: '#6b57be'}"/>
        </a>
      </button>
    </div>
  </header>
</template>

<script setup lang="ts">
import { GithubFilled, SyncOutlined } from '@ant-design/icons-vue';
import { GITHUB_URL, LOGO_URL } from '../utils/WebConstants.ts';

interface Tab {
  id: string;
  name: string;
}

interface Props {
  tabs: Tab[];
  activeTab: string;
}

const props = defineProps<Props>();
const emit = defineEmits<{
  (e: 'switch-tab', tabId: string): void;
  (e: 'refresh'): void;
}>();

const switchTab = (tabId: string) => {
  emit('switch-tab', tabId);
};

const refreshCurrentTab = () => {
  emit('refresh');
};
</script>

<style scoped>
/* 导航栏模糊效果 */
header {
  background-color: rgba(58, 42, 42, 0.7); /* 半透明深棕色背景 */
  backdrop-filter: blur(10px); /* 模糊效果 */
  color: white;
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #553d3d;
  position: relative;
}

.logo-container {
  display: flex;
  align-items: center;
  gap: 0.8rem;
}

.logo {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  color: white;
  font-weight: bold;
  text-transform: uppercase;
}

.title {
  display: flex;
  flex-direction: column;
  font-weight: bold;
}

.title h1 {
  font-size: 1.8rem;
  margin: 0;
  color: white;
}

.title p {
  font-size: 1.2rem;
  color: #e74c3c;
  margin: 0;
}

.version {
  font-size: 0.8rem;
  color: #ccc;
  margin-left: 0.5rem;
}

.nav-tabs {
  display: flex;
  gap: 0.8rem;
  border: 1px solid #553d3d;
  border-radius: 20px;
  padding: 0.2rem;
  background-color: rgba(255, 255, 255, 0.05);
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1;
}

.tab-btn {
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  color: #ccc;
  cursor: pointer;
  font-size: 0.9rem;
  transition: color 0.2s;
}

.tab-btn:hover {
  color: white;
}

.tab-btn.active {
  color: #e74c3c;
  font-weight: bold;
}

.right-icons {
  display: flex;
  gap: 1rem;
}

.icon-btn {
  background: none;
  border: none;
  color: #e74c3c;
  cursor: pointer;
  font-size: 1.2rem;
  padding: 0.3rem;
}

.refresh-icon,
.cat-icon {
  font-size: 1.2rem;
}

@media (max-width: 768px) {
  header {
    padding: 1rem;
    flex-direction: column;
    gap: 1rem;
  }

  .logo-container {
    flex-direction: column;
    align-items: flex-start;
  }

  .title h1 {
    font-size: 1.5rem;
  }

  .title p {
    font-size: 1rem;
  }

  .nav-tabs {
    width: 100%;
    justify-content: center;
    position: relative;
    left: auto;
    transform: none;
  }

  .right-icons {
    width: 100%;
    justify-content: flex-end;
  }
}
</style>
